#include<bits/stdc++.h>
using namespace std;
const int N = 60;
bool vis[N];
int MOD;
int qpow(int x,int p){
	int res = 1;
	while(p){
		if(p & 1){
			res = 1ll*res*x%MOD;
		}
		x = 1ll*x*x%MOD;
		p >>= 1;
	}
	return res;
}
vector<int> bian[N];
int fcnt = 0;
void dfs(int x){
	fcnt++;
	vis[x] = 1;
	for(int v: bian[x]){
		if(vis[v])continue;
		dfs(v);
	}
}
const int MC = 21;
int f[MC][MC],g[MC][MC];

int main(){
	//freopen("debug.in","r",stdin);
	int a,b,c,m;
	cin>>a>>b>>c>>m>>MOD;
	int n = a + b + c;
	int ans = 0;
	vector<vector<int>> tss(0);
	{
		vector<int> val;
		for(int i = 1;i<=n;i++){
			val.push_back(i);
		}
		tss.push_back(val);
	}
	for(int i = 1;i<=m;i++){
		vector<int> val;
		for(int i = 1;i<=n;i++){
			int x;
			cin>>x;
			val.push_back(x);
		}
		tss.push_back(val);
	}
	stable_sort(tss.begin(),tss.end());
	tss.erase(unique(tss.begin(),tss.end()),tss.end());
	m = tss.size();
	//cerr<<tss.size()<<'\n';
	for(int i = 1;i<=m;i++){
		for(int i = 1;i<=n;i++){
			bian[i].clear();
		}
		for(int j = 1;j<=n;j++)
		{
			int x = tss[i - 1][j - 1];
			bian[x].push_back(j);
			bian[j].push_back(x);
		}
		memset(vis,0,sizeof(vis));
		int ccnt = 0;
		vector<int> val;
		for(int i = 1;i<=n;i++){
			if(!vis[i]){
				fcnt = 0;
				dfs(i);
				val.push_back(fcnt);
			}
		}
		memset(f,0,sizeof(f));
		f[a][b] = 1;
		int ksiz = 0;
		for(int sz : val){
			//cerr<<sz<<'\n';
			for(int j = 0;j <= a;j++){
				for(int k = 0;k <= b;k++){
					if(j >= sz){
						g[j - sz][k] = (g[j - sz][k] + f[j][k])%MOD;
					}
					if(k >= sz){
						g[j][k - sz] = (g[j][k - sz] + f[j][k])%MOD;
					}
					if(n - ksiz - j - k >= sz){
						g[j][k] = (g[j][k] + f[j][k])%MOD;
					}
				}
			}
			ksiz -= sz;
			memcpy(f,g,sizeof(f));
			memset(g,0,sizeof(g));
		}
		ans = (ans + f[0][0])%MOD;
	}
	ans = 1ll*ans*qpow(m,MOD - 2)%MOD;
	cout<<ans<<'\n';
}